library MarineQuickFire initializer init requires LegacySystem


	private function QuickFireConditions takes nothing returns boolean
		return GetSpellAbilityId()=='A07S'
	endfunction

	private function QuickFire takes nothing returns nothing
		local unit u = GetTriggerUnit()
		local integer inven = 0
		local item i
		local integer id
		local location l = GetSpellTargetLoc()
		local real x = GetLocationX(l)
		local real y = GetLocationY(l)
		loop
			exitwhen inven>5
			set i = UnitItemInSlot(u,inven)
			set id = GetItemTypeId(i)
			if id=='I008' or id=='I009' then //Benelli,Browning
				call UnitUseItemPoint(u,i,x,y)
				set inven=1337
			endif
			set inven=inven+1
		endloop
		if inven<1337 and GetWidgetLife(u)<180.0 then
			set inven=0
			loop
				exitwhen inven>5
				set i = UnitItemInSlot(u,inven)
				set id = GetItemTypeId(i)
				if id=='I004' and GetUnitAbilityLevel(u,'Brej')<=0 and GetUnitAbilityLevel(u,'B00H')<=0 then //Medkit
					call UnitUseItemTarget(u,i,u)
					set inven=1337
				elseif id=='phea' then //Fibrin
					call UnitUseItem(u,i)
					set inven=1337
				endif
				set inven=inven+1
			endloop
		endif
		call RemoveLocation(l)
		set l = null
		set i = null
		set u = null
	endfunction

	private function init takes nothing returns nothing
		local trigger t
		set t = CreateTrigger()
		call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_CHANNEL  )
		call TriggerAddCondition(t,Condition(function QuickFireConditions))
		call TriggerAddAction(t,function QuickFire)
	endfunction




endlibrary